<?php

ignore_user_abort(true);
set_time_limit(1200);



require '../!inc.php';

if (!defined('BR')) {
    define('BR', "\n<BR>");
}

/**
 * Set names of blocks and location
 * file that you going to import
 * 
 * Get these files from MaxMind website:
 * http://www.maxmind.com/app/geolitecity
 * 
 * Choose to download GeoLite City in csv format
 * then unzip the downloade zip file
 * and copy the 2 .csv files in this directory
 * (2 files will approximately 150MB total)
 * 
 * Make sure to upload them in ASCII mode
 * (your ftp client/server must be set to transfer the .csv files
 * in ASCII mode)
 * 
 * If you want, you may also buy the non-free versions from MixMind, 
 * in which case
 * you would change the names of the 2 files below
 * to the names of files that came with your full version of 
 * GeoCity .cvs files.
 * 
 * Then just run this geo_import.php file via web browser.
 * It may take 5-10 minutes to complete the import,
 * the importer script imports over 4 million records one by one
 * then creating 2 indexes in the database
 * 
 * After the importing is done you should delete these .csv files
 * If you don't delete them then anyone can lauhch this file with a browser
 * and it will start the import all over again.
 * 
 * If you want to later upgrade to latest files from MaxMind site
 * just upload the new .csv files and run this script again - it will
 * drop the previously impored DB collections and import new files.
 * 
 * 
 * 
 */
$start = microtime(true);
$blocksFile = 'GeoLiteCity-Blocks.csv';

$locationFile = 'GeoLiteCity-Location.csv';

// DO NOT EDIT ANYTHING BELOW

$dir = dirname(__FILE__);
//
$b = $dir . DIRECTORY_SEPARATOR . $blocksFile;
$l = $dir . DIRECTORY_SEPARATOR . $locationFile;
if (!is_readable($l)) {
    throw new \Exception('File ' . $locationFile . ' is not found in this directory ' . $dir . ' or is not readable to php');
}

if (!is_readable($b)) {
    throw new \Exception('File ' . $blocksFile . ' is not found in this directory ' . $dir . ' or is not readable to php');
}


$Importer = new \StudyBuddy\Geo\Import($oRegistry->Mongo->getDb(), $b, $l);
$Importer->run();
$end = microtime(true);
echo BR . 'Importing done in ' . ($end - $start) . ' seconds';
